<template>
  <div class="My_info">
    <div class="My_myIcon">
      <img class="My_avatar" src="http://liufusong.top:8080/img/profile/avatar.png" alt="icon" />
    </div>
    <div class="My_user">
      <div class="My_name">{{ username }}</div>
      <van-button type="primary" round size="small" @click="goOut">退出</van-button>
      <div class="My_mine">编辑个人资料<van-icon name="play" /></div>
    </div>
  </div>
</template>

<script>
import { Dialog } from 'vant'
import { removeToken } from '@/utils/storage'
import { userMessage } from '@/api/user'
export default {
  name: 'MyInfo',
  data() {
    return {
      username: ''
    }
  },
  async created() {
    const data = await userMessage()
    // console.log(data)
    this.username = data.body.nickname
  },
  methods: {
    goOut() {
      Dialog.confirm({
        title: '提示',
        message: '是否确定退出？'
      }).then(() => {
        removeToken()
        location.reload()
      })
    }
  }
}
</script>

<style scoped>
.My_info {
  position: absolute;
  background: #fff;
  width: 74%;
  height: 55%;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: 0 0 10px 3px #ddd;
  margin: 50px auto 0;
  padding: 0 20px;
  text-align: center;
  font-size: 13px;
  z-index: 1;
}
.My_avatar {
  width: 100%;
  border-radius: 50%;
}
.My_myIcon {
  position: relative;
  transform: translateY(-50%);
  border-radius: 50%;
  width: 60px;
  height: 60px;
  border: 5px solid #f5f5f5;
  display: inline-block;
  box-shadow: 0 2px 2px #bdbdbd;
}
.My_name {
  margin-top: -17px;
  margin-bottom: 5px;
}
button {
  width: 50px !important;
  height: 20px !important;
  margin-bottom: 10px !important;
}
.My_mine {
  font-size: 12px !important;
  color: #999;
  margin-top: 20px;
}
</style>
